package com.zhanglijie.improve.aqs.aqsandsync;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/9/11 0011 14:08
 */
public class AqsState {
    ReentrantLock reentrantLock = new ReentrantLock();
    public   void one(){//state ++
        try{
            reentrantLock.lock();
            System.out.println(Thread.currentThread()+"进入one方法"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
            two();
            Thread.sleep(2000);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            reentrantLock.unlock(); //state --
        }

    }

    private   void two() {//state ++

        System.out.println(Thread.currentThread()+"进入two方法"+new SimpleDateFormat("HH:mm:ss").format(new Date()));
        try{
            reentrantLock.lock();
            Thread.sleep(2000);
        }catch (Exception e){

        }
        finally {
            reentrantLock.unlock(); //state --
        }

    }

    public static void main(String[] args) {
        // AqsState aqsState = new AqsState();
        // new Thread(()->aqsState.one()).start();
        // new Thread(()->aqsState.two()).start();
        int i = Integer.numberOfLeadingZeros(4);
        System.out.println(i);
    }
}
